export VERSION = 0.0.4
export TOPDIR = $(shell pwd)
export DISTDIR = $(TOPDIR)/sysreport-$(VERSION)
export prefix = /usr
export sysconfdir = /etc
export bindir = $(prefix)/bin
export datadir = $(prefix)/share
export libdir = $(prefix)/lib
export mandir = $(prefix)/share/man

bin_files = sysreport
extra_files = \
	Makefile \
	cron.sysreport \
	sysreport.1 \
	NEWS \
	COPYING \
	TODO \
	README 
source_files = \
	src/*.cs 

dist_files = $(bin_files) $(extra_files) $(source_files)

.PHONY: clean dist install 

build: SysReport.exe

SysReport.exe:
	mcs -out:SysReport.exe src/*.cs

install-mkdirs:
	mkdir -p $(DESTDIR)$(bindir)
	mkdir -p $(DESTDIR)$(mandir)/man1
	mkdir -p $(DESTDIR)$(libdir)/SysReport
	mkdir -p $(DESTDIR)$(datadir)/SysReport

install: SysReport.exe install-mkdirs
	install -m 755 sysreport $(DESTDIR)$(bindir)
	install -m 755 cron.sysreport $(DESTDIR)$(datadir)/SysReport
	install -m 644 SysReport.exe $(DESTDIR)$(libdir)/SysReport
	install -m 644 sysreport.1 $(DESTDIR)$(mandir)/man1

clean:
	rm SysReport.exe

dist: $(dist_files)
	if ! grep "^Changes in $(VERSION)" NEWS > /dev/null 2>&1; then \
		echo "no NEWS entry"; \
		exit 1; \
	fi
	rm -rf $(DISTDIR)
	mkdir $(DISTDIR)
	for f in $(dist_files); do \
		mkdir -p $(DISTDIR)/`dirname $$f`; \
		cp -a $$f $(DISTDIR)/$$f; \
	done; \
	tar cjf $(DISTDIR).tar.bz2 `basename $(DISTDIR)`

distcheck: dist
